import socket
import json

def get_base_url(ip, port, use_https=True):
    protocol = "https" if use_https else "http"
    if use_https and port == 443:
        return f"{protocol}://{ip}"
    elif not use_https and port == 80:
        return f"{protocol}://{ip}"
    return f"{protocol}://{ip}:{port}"

def generate_url(ip, port, endpoint, use_https=True):
    base_url = get_base_url(ip, port, use_https)
    if endpoint.startswith('/'):
        endpoint = endpoint[1:]
    return f"{base_url}/{endpoint}/"


def get_shared_headers():
    config = load_config()
    return config.get("headers", {})

def get_shared_ip():
    host_name = socket.gethostname()
    return socket.gethostbyname(host_name)

def get_shared_port():
    return "8008"

def load_config():
    with open("config.json", "r", encoding="utf-8") as config_file:
        return json.load(config_file)

if __name__ == "__main__":
    config = load_config()
    print("Loaded Config:", config)
